<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="js/jquery.min.js"></script>
    <title>Document</title>
    <script>
        // ajax 提交
        function mysub(){
            // 1.判空
            var username = jQuery("#username");
            var password = jQuery("#password");
            if(jQuery.trim(username.val())==""){
                alert("请先输入用户名！");
                username.focus(); // 光标重制到此元素
                return;
            }
            if(jQuery.trim(password.val())==""){
                alert("请先输入密码！");
                password.focus(); // 光标重制到此元素
                return;
            }
            // $.ajax({
            //     url: "user/login",
            //     type: "POST",
            //     contentType: "application/Json",
            //     data:JSON.stringify({"username":username.val(),
            // "password":password.val()}),   必须用json对象接收
            //     success: function(result) {
            //         alert(result);
            //     }
            // })

            //可以用参数方式接收
            jQuery.ajax({
                url:"/user/login",
                type:"POST",
                data: {"username":username.val(),
            "password":password.val()},
                success:function(result){
                    alert(JSON.stringify(result));
                }
            });
        }
    </script>
</head>
<body>
<div style="text-align: center;">
    <h1>登录</h1>
    用户：<input id="username">
    <br>
    密码：<input id="password" type="password">
    <br>
    <input type="button" value=" 提交 " onclick="mysub()" style="margin-top: 20px;margin-left: 50px;">
</div>
</body>
</html>